var config = require("config");
//道具组
var bossG = cc.Class({
    name:'bossG',
    properties: {
        name:'',
        freqTime:0,
        initPollCount:0,
        prefab:cc.Prefab
    }
});

cc.Class({
    extends: cc.Component,

    properties:()=>({
        bossG: {
            default:[],
            type: bossG
        },
        main: {
            default: null,
            type: require('main'),
        },
        propGroup: {
            default: null,
            type: require('propGroup'),
        },
    }),
    
    // use this for initialization
    onLoad: function () { 
        //初始化道具组
        this.eState = D.commonInfo.gameState.none;
        D.common.batchInitObjPool(this,this.bossG);
    },
    startAction: function(){
        this.eState = D.commonInfo.gameState.start;
        // var index = Math.floor(Math.random()*2);
        var newV2 = cc.v2(0,540);
        this.getNewEnemy(this.bossG[0],newV2);
    },
    //重新开始
    resumeAction: function(){
        this.enabled = true;
        this.eState = D.commonInfo.gameState.start;
    },
    //暂停
    pauseAction: function(){
        this.enabled = false;
        this.eState = D.commonInfo.gameState.pause;
    },
    //生成道具
    getNewEnemy: function(enemyInfo,newV2) {
        var poolName = enemyInfo.name + 'Pool';
        var newNode = D.common.genNewNode(this[poolName],enemyInfo.prefab,this.node);
        newNode.setPosition(newV2);
        newNode.getComponent('boss').init();

        this.boss = newNode.getComponent('boss');
    },
    //道具随机生成的位置
    getNewEnemyPositon: function(newEnemy) {
        //位于上方，先不可见
        var randx = Math.random()*(this.node.parent.width/2-newEnemy.width/2);
        var randy = this.node.parent.height/2+newEnemy.height/2;
        return cc.v2(randx,randy);
    },
    enemyDied: function(nodeinfo,score){
        //回收节点
        D.common.backObjPool(this,nodeinfo);
        //增加分数
        // if (parseInt(score)>0){
        //     this.main.gameCoinAdd(parseInt(score));
        // }  
    },
    getScore: function(){
        return this.main.getScore();
    },
    //获取英雄位置
    getHeroPos: function(){
        return this.main.getHeroPos();
    },
    getBossPos(){
        return this.boss.getPosition();
    },
    //生成道具
    initProp(newV2){
        this.propGroup.startAction(newV2);
    }, 
});
